package views
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	
	import gs.TweenLite;
	
	public class VMain extends Sprite
	{
		public static const START:String = "START";
		public static const GAME:String = "GAME";
		
		private var currentView:Sprite = new Sprite();
		private var tweener:TweenLite;
		
		public function VMain()
		{
			super();
			
			currentView = new VStart();
			this.addChild(currentView);
			
			this.addEventListener(ViewEvent.CHANGE_VIEW, onViewChange);
		}
		
		private function onViewChange(e:ViewEvent):void
		{
			if(this.contains(currentView))
			{
				tweener = new TweenLite(currentView, 0.5, {alpha: 0, onComplete:onViewChangeEnd, onCompleteParams:[currentView]});
				//this.removeChild(currentView);
			}
			currentView = getView(e);
			currentView.alpha = 0;
			tweener = new TweenLite(currentView, 0.5, {alpha: 1});
			this.addChild(currentView);
		}
		
		private function onViewChangeEnd(obj:DisplayObject):void
		{
			this.removeChild(obj);
		}
		
		private function getView(e:ViewEvent):Sprite
		{
			switch(e.nextView)
			{
				case START:
					return new VStart();
					break;
				case GAME:
					return new VGame();
					break;
			}
			return null;
		}
	}
}